﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

public class DepartmentManager : System.Web.Services.WebService
{

    private DepartmentBL _DepartmentBL = new DepartmentBL();

    [WebMethod]
    [System.Xml.Serialization.XmlInclude(typeof(Department))]
    public ResultObject GuardarDepartamento(string id, string nombre)
    {

        Department department = new Department();
        if (id != "")
            department.DepartmentId = long.Parse(id);
        else
            department.DepartmentId = 0;
        department.Name = nombre;


        try
        {
            _DepartmentBL.GuardarDepartmento(department);
            return new ResultObject("ok", null);
        }
        catch (Exception ex)
        {
            return new ResultObject("No fue posible modificar el Departamento", null);
        }
    }

    [WebMethod]
    [System.Xml.Serialization.XmlInclude(typeof(Usuario))]
    public ResultObject BorrarDepartmento(string id)
    {
        try
        {
            _DepartmentBL.DeleteDepartment(id);
            return new ResultObject("ok", null);
        }
        catch (Exception ex)
        {

            return new ResultObject("No fue posible borrar el departamento", null);
        }
    }

    [WebMethod]
    public List<string> ObtenerDepartamentos()
    {
        try
        {
            List<string> department;
            department = _DepartmentBL.ObtenerDepartmentos();
            return department;
        }
        catch (Exception ex)
        {
            List<string> error = new List<string>();
            
            error.Add(" No fue posible borrar el departamento");
            return error;
        }
    }

    [WebMethod]
    public long ObtenerJefeDeDepartamento(string departamento)
    {
        try
        {
            long usuario = 0;
            usuario = _DepartmentBL.ObtenerJefeDeDepartmento(departamento);
            return usuario;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }


}
